from django.shortcuts import render
from django.http import HttpResponse
from django.template.response import TemplateResponse
from django.conf import settings

from docker import Client


# Create your views here.
def index(request):
    client = Client(base_url=settings.DOCKER_BASE_URL)
    images = client.images()
    image_list = []
    for img in images:
        image_list.append({"repository": img.get('RepoTags')[0],
            "tag": img.get('RepoTags')[0],
            "image_id": img.get('Id'),
            "created": img.get('Created'),
            "virtual_size": int(img.get('VirtualSize'))/1024/1024})
    return render(request,
                  'login/index.html',
                  {"image_list": image_list})


def login(request):
    # return TemplateResponse(request, 'login/login.html', {})
    return render(request, 'login/login.html')